package org.etom.impl.ui.common;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;

/**
 * The listener listen for the new project and
 * provides via its interface.
 */
public class NewProjectListener implements IResourceChangeListener {

  private IProject project;
  
  /**
   * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
   */
  @Override
  public void resourceChanged(IResourceChangeEvent event) {
    IResourceDelta delta = event.getDelta();
    if (null == delta) return;
    IResourceDelta[] deltaChildren = delta.getAffectedChildren();
    for (IResourceDelta child : deltaChildren) {
      if ((IResourceDelta.ADDED == child.getKind())
        &&(child.getResource() instanceof IProject)) {
        project = (IProject) child.getResource();
        break;
      }
    }
  }

  /**
   * The method returns the new project.
   * <code>null</code> if the new project is not available.
   * 
   * @return - the new project
   */
  public IProject getProject() {
    return project;
  }
  
}
